package com.itheima.bos.service.base.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itheima.bos.dao.base.ICourierRepository;
import com.itheima.bos.dao.base.IFixedAreaRepository;
import com.itheima.bos.dao.base.ITakeTimeRepository;
import com.itheima.bos.domain.base.Courier;
import com.itheima.bos.domain.base.FixedArea;
import com.itheima.bos.domain.base.TakeTime;
import com.itheima.bos.service.base.IFixedAreaService;
import com.itheima.bos.service.base.ITakeTimeSerivce;
@Service
@Transactional
public class FixedAreaServiceImpl implements IFixedAreaService {

	//注入dao层
	@Autowired
	private IFixedAreaRepository fixedAreaRepository;
	@Autowired
	private ICourierRepository courierRepository;
	@Autowired
	private ITakeTimeRepository takeTimeRepository;
	
	//保存定区
	@Override
	public void sava(FixedArea model) {
		fixedAreaRepository.save(model);
	}

	@Override
	public Page<FixedArea> findPageData(Specification<FixedArea> specification,
			Pageable pageable) {
		
		return fixedAreaRepository.findAll(specification,pageable);
	}
	
	//快递员关联定区
	@Override
	public void associationCouriertoFixedArea(FixedArea model,
			Integer courierId, Integer takeTimeId) {
		FixedArea fixedArea = fixedAreaRepository.findOne(model.getId());
		Courier courier = courierRepository.findOne(courierId);
		TakeTime takeTime = takeTimeRepository.findOne(takeTimeId);
		
		fixedArea.getCouriers().add(courier);
		
		courier.setTakeTime(takeTime);
	}
	
	

}
